// 媒体频道对比
var ComparePageObject = {
	PageDivContentID : "CarCompareContent", // container id
	PageDivContentObj : null, // container object
	IsDelSame : false,
	IsOperateTheSame : false,
	AllCarJson : new Array(),
	ArrPageContent : new Array(),
	ArrTempBarHTML : new Array(),
	ArrTempBarForFloatLeftHTML : new Array(),
	ArrTempLeftNavHTML : [],
	ArrLeftNavHTML : [],
	ArrTempHideLeftNavId : [],
	ArrHideLeftNavIds : [],
	FloatTop : new Array(),
	FloatLeft : new Array(),
	ValidCount : 0,
	MaxTDLeft : 5,
	NeedBlockTD : 0,
	DragID : "",
	DropID : "",
	OtherCarInterface : "",
	LastFirstInterface : Array(),
	IsCloseHotList : false,
	CreateSelectChange : new Array(),
	SelectControlTemp : "",
	BSelect : null,
	BaikeObj : null,
	IsShowFloatTop : false,
	arrCarIds : [],
	IsShowDiff : true, // 差异显示
	IsVantage : true, // 优势项 默认选中
	IE6 : !-[ 1, ] && !window.XMLHttpRequest,
	IE7 : navigator.userAgent.toLowerCase().indexOf("msie 7.0") != -1,
	IsIE : (navigator.appName == "Microsoft Internet Explorer"),
	IsChange : false
}

function initPageForCompare() {
	intiSelectControl();
	if (document.getElementById(ComparePageObject.PageDivContentID)) {
		ComparePageObject.PageDivContentObj = $("#"
				+ ComparePageObject.PageDivContentID);
	}
	if (typeof (carCompareJson) != "undefined" && carCompareJson != null) {
		ComparePageObject.AllCarJson = carCompareJson;
	}
	ComparePageObject.ValidCount = ComparePageObject.AllCarJson.length;
	ComparePageObject.NeedBlockTD = ComparePageObject.ValidCount >= 5 ? 1
			: 5 - ComparePageObject.ValidCount;
	if (ComparePageObject.ValidCount == 10) {
		ComparePageObject.NeedBlockTD = 0;
	}
	var hash = window.location.hash;
	if (hash.indexOf("&vantage") != -1)
		ComparePageObject.IsVantage = true;
	if (hash.indexOf("&diff") != -1)
		ComparePageObject.IsOperateTheSame = true;
	if (hash.indexOf("&showdiff") != -1)
		ComparePageObject.IsShowDiff = true;
	// 初始化 左上角多选框选中状态
	if (ComparePageObject.IsVantage)
		$("#smallfixed input[name='chkAdvantage']").attr("checked", true);
	if (ComparePageObject.IsOperateTheSame)
		$("#smallfixed input[name='checkboxForDelTheSame']").attr("checked",
				true);
	if (ComparePageObject.IsShowDiff)
		$("#smallfixed input[name='checkboxForDiff']").attr("checked", true);

	checkIsCloseHotCompare();
	createPageForCompare(ComparePageObject.IsOperateTheSame);

}

// 构建空表格数据
function createEmptyTable() {
	var flag = false;
	for ( var i = 0; i < arrField.length; i++) {
		if (arrField[i].sType == "bar" && arrField[i]["sFieldTitle"] == "车体")
			break;
		if (arrField[i].sType == "bar" && arrField[i]["sFieldTitle"] == "基本信息") {
			var arrFieldRow = arrField[i];
			flag = true;
			ComparePageObject.ArrPageContent.push("<tr id=\""
					+ arrFieldRow.scrollId + "\"><td class=\"pd0\" colspan=\""
					+ (ComparePageObject.MaxTDLeft + 1)
					+ "\"><h2><span>基本信息</span></h2></td></tr>");
		}
		ComparePageObject.ArrPageContent.push("<tr>");
		if (arrField[i].sType == "fieldPara" && flag) {
			var arrFieldRow = arrField[i];
			ComparePageObject.ArrPageContent.push("<th>"
					+ checkBaikeForTitle(arrFieldRow) + "</th>");
			for ( var j = 0; j < ComparePageObject.MaxTDLeft; j++) {
				ComparePageObject.ArrPageContent.push("<td name=\"td" + j
						+ "\"></td>");
			}
		}
		ComparePageObject.ArrPageContent.push("</tr>");
	}
}
function createPageForCompare(isDelSame) {
	if (ComparePageObject.ValidCount <= 0) {
		$("#left-nav").hide();
	}
	ComparePageObject.IsDelSame = isDelSame;
	var loopCount = arrField.length;
	ComparePageObject.ArrPageContent
			.push("<table cellspacing=\"0\" cellpadding=\"0\"><tbody>");
	for ( var i = 0; i < loopCount; i++) {
		switch (arrField[i].sType) {
		case "fieldPara":
			if (ComparePageObject.ValidCount > 0)
				createPara(arrField[i]);
			break;
		case "bar":
			if (ComparePageObject.ValidCount > 0)
				createBar(arrField[i]);
			break;
		case "fieldPic":
			createPic();
			break;
		}
	}
	// 创建空数据
	if (ComparePageObject.ValidCount <= 0)
		createEmptyTable();

	ComparePageObject.ArrPageContent.push("</tbody></table>");
	// end
	if (ComparePageObject.PageDivContentObj) {
		ComparePageObject.PageDivContentObj
				.html(ComparePageObject.ArrPageContent.join(""));
	}
	ComparePageObject.ArrPageContent.length = 0;
	// set img drag
	setImgDrag();
	if (!ComparePageObject.IsCloseHotList) {
		ajaxOtherCarList();
	}
	bindSelectForCompare();
	changeWhenFloatTop();
	if (ComparePageObject.ValidCount > 0) {
		$("#leftfixed").html(
				"<table cellpadding=\"0\" cellspacing=\"0\" class=\"floatTable\">"
						+ ComparePageObject.FloatLeft.join("") + "</table>");
		ComparePageObject.FloatLeft.length = 0;
	}
	// 填充左侧滚动菜单
	if (ComparePageObject.ValidCount > 0) {
		$("#left-nav ul").html(ComparePageObject.ArrLeftNavHTML.join('')).find(
				"li:last").addClass("last").show();
		ComparePageObject.ArrLeftNavHTML.length = 0;
	}

	// alert(ComparePageObject.ArrHideLeftNavIds.join(''));
	// $("#left-nav li a[data-target='" + n + "'").closest("li").hide();

	ComparePageObject.ArrHideLeftNavIds.length = 0;
	changeCheckBoxStateByName("checkboxForDelTheSame",
			ComparePageObject.IsOperateTheSame);
	setTRColorWhenMouse();

	// 绑定事件
	bindEvent();
}

// 绑定事件
function bindEvent() {
	// 左侧隐藏按钮
	$(".btn-show-left-nav").click(function() {
		$("#left-nav").show().addClass("left-nav-horizontal");
		$(".btn-hide-left-nav").show();
		$(this).hide();
	});
	// 菜单隐藏按钮
	$(".btn-hide-left-nav").click(function() {
		$("#left-nav").removeClass("left-nav-horizontal");
		$(this).hide();
		$(".btn-show-left-nav").show();
	});

	// 添加滚动监听事件
	$('[data-spy="scroll"]').each(function() {
		var $spy = $(this);
		$spy.scrollspy($spy.data(), function() {
			scrollCallback();
		});
		$spy.scrollspy("refresh");
	});
	// 元素切换效果
	// $("div[id^='tableHead_']").clickChange({ "leftCallback":
	// moveLeftForCarCompare, "rightCallback": moveRightForCarCompare });
	$(".tableHead_item").clickChange({
		"leftCallback" : moveLeftForCarCompare,
		"rightCallback" : moveRightForCarCompare
	});
	if (ComparePageObject.ValidCount <= 0) {
		$("#left-nav").hide();
		$(window).scrollTop(0);
	} else {
		$("#left-nav").show();
	}
	// 点击空白 换车 推荐 弹出层隐藏
	$(document)
			.click(
					function(e) {
						// e.preventDefault();
						e = e || window.event;
						var target = e.srcElement || e.target;
						// console.log(($(target).closest(".popup-change-car").length
						// <= 0));
						// console.log((target.id != undefined &&
						// target.id.indexOf("change_car_") == -1));
						// 换车
						if (($(target).closest(".popup-change-car").length <= 0)
								&& ($(target).closest("a[id^='change_car_']").length <= 0)) {
							$(".change-car-area a[id^='change_car_']").attr(
									"class", "btn-show-car").siblings(
									".popup-change-car").hide();
						}
						// 为我推荐
						if ($(target).closest(".popup-recom").length <= 0
								&& ($(target).closest(".btn-hide-car").length <= 0)) {
							$(".recom-car > a:first-child").attr("class",
									"btn-show-car").siblings(".popup-recom")
									.hide();
						}
					});
}
// 已选车款不可选
function setCarDisabled() {
	for ( var i = 0; i < ComparePageObject.ValidCount; i++) {
		var carId = ComparePageObject.AllCarJson[i][0][0];
		$("#cartype4 .popup-box .select-list a[bita-value='" + carId + "']")
				.unbind("click").addClass("none");
		$(
				"div[id^='CarTypeSelectList_'] .popup-box .select-list a[bita-value='"
						+ carId + "']").unbind("click").addClass("none");
	}
}
// create pic for compare
function createPic() {
	ComparePageObject.ArrPageContent.push("<tr id=\"trForPic\">");
	var classNameAdd = "";
	if (!ComparePageObject.IsCloseHotList) {
		// classNameAdd = " bdbottomnone";
	}
	ComparePageObject.ArrPageContent.push("<th class=\"pd0" + classNameAdd
			+ "\">");
	ComparePageObject.ArrPageContent.push("<div class=\"tableHead_left\">");
	ComparePageObject.ArrPageContent
			.push("<dl><dt>属性参数对比</dt><dd>拖拽媒体图片可调顺序</dd></dl>");

	ComparePageObject.ArrPageContent
			.push("<div class=\"check-box-item\"><input type=\"checkbox\" name=\"chkAdvantage\" onclick=\"advantageForCompare();\" "
					+ (ComparePageObject.IsVantage ? "checked" : "")
					+ "> <label for=\"chkAdvantage\">标识优势项 <em></em></label></div>");
	ComparePageObject.ArrPageContent
			.push("<div class=\"check-box-item\"><input type=\"checkbox\" name=\"checkboxForDiff\" onclick=\"showDiffForCompare();\" "
					+ (ComparePageObject.IsShowDiff ? "checked" : "")
					+ "> <label for=\"checkboxForDiff\">高亮不同项</label></div>");
	ComparePageObject.ArrPageContent
			.push("<div class=\"check-box-item\"><input type=\"checkbox\" name=\"checkboxForDelTheSame\" onclick=\"delTheSameForCompare();\"> <label for=\"checkDiffer\">隐藏相同项</label></div>");

	ComparePageObject.ArrPageContent.push("</th>");

	for ( var i = 0; i < ComparePageObject.ValidCount; i++) {
		ComparePageObject.ArrPageContent.push("<td class=\"pd0" + classNameAdd
				+ "\" name=\"td" + i + "\" id=\"td_" + i
				+ "\" style=\"position:relative; z-index:" + (10 - i) + "\" >");
		if (i == 0) {
			ComparePageObject.ArrPageContent.push("<div id=\"tableHead_" + i
					+ "\" class=\"tableHead_item\">");
		} else {
			ComparePageObject.ArrPageContent.push("<div id=\"tableHead_" + i
					+ "\" class=\"tableHead_item\">");
		}
		ComparePageObject.ArrPageContent
				.push("<div class=\"sel-car-box\" id=\"carBox_" + i + "\">");
		var pic = ComparePageObject.AllCarJson[i][0][2] || "";
		pic == "" ? "http://image.bitautoimg.com/autoalbum/V2.1/images/120-80.gif"
				: pic;

		ComparePageObject.ArrPageContent.push("<div style=\"height:120px\">");
		ComparePageObject.ArrPageContent.push("<div id=\"draggcarbox_" + i
				+ "\" class=\"sel-car-move\">");
		ComparePageObject.ArrPageContent.push("<img id=\"imgdrag_" + i
				+ "\" name=\"imgdrag\" alt=\"按住鼠标左键，可拖动到其他列\" src=\"" + pic
				+ "\">");
		var yearType = ComparePageObject.AllCarJson[i][0][7];
		ComparePageObject.ArrPageContent
				.push("<dl><dt><a target=\"_blank\" href=\""
						+ ComparePageObject.AllCarJson[i][0][3] + "/\">"
						+ ComparePageObject.AllCarJson[i][0][1] + "</a></dt>");

		
		ComparePageObject.ArrPageContent.push("</dl>");
		ComparePageObject.ArrPageContent.push("</div>");
		ComparePageObject.ArrPageContent.push("</div>");

		ComparePageObject.ArrPageContent
				.push("<div class=\"change-car-area\">");
		ComparePageObject.FloatTop.push("</div></div>");

		if (i > 0) {
			ComparePageObject.ArrPageContent
					.push("<a class=\"btn-pre-car\" href=\"javascript:;\" title=\"左移\"></a>");
			// for FloatTop
			ComparePageObject.FloatTop
					.push("<a class=\"btn-pre-car\" href=\"javascript:;\" title=\"左移\"></a>");
			ComparePageObject.ArrPageContent
			.push("<a class='btn-top' href='javascript:;'><span><<置顶</span></a>");
		}



		if (i != ComparePageObject.ValidCount - 1) {
			// ComparePageObject.ArrPageContent.push("<a class=\"btn-next-car\"
			// href=\"javascript:moveRightForCarCompare('" + i + "');\"></a>");
			ComparePageObject.ArrPageContent
					.push("<a class=\"btn-next-car\" href=\"javascript:;\" title=\"右移\"></a>");
			// for FloatTop
			ComparePageObject.FloatTop
					.push("<a class=\"btn-next-car\" href=\"javascript:;\" title=\"右移\"></a>");
		}
		ComparePageObject.ArrPageContent.push("</div>");
		ComparePageObject.ArrPageContent
				.push("<a class=\"btn-close-car\" title=\"删除\" href=\"javascript:;\" onclick=\"delCarToCompare('"
						+ i + "',event);\">删除</a>");

		ComparePageObject.ArrPageContent.push("</div>");
		ComparePageObject.FloatTop.push("</div>");
		ComparePageObject.FloatTop
				.push("<a class=\"btn-close-car\" title=\"删除\" href=\"javascript:;\" onclick=\"delCarToCompare('"
						+ i + "',event);\">删除</a>");
		ComparePageObject.ArrPageContent.push("</div>");
		if (i == 0) {
			// ComparePageObject.ArrPageContent.push("<div
			// style=\"display:none;\" class=\"firstCar_pop\"
			// id=\"firstCar_pop\"></div>");
		}
		ComparePageObject.ArrPageContent.push("</td>");

		// for FloatTop
		ComparePageObject.FloatTop.push("</div>");
		ComparePageObject.FloatTop.push("</td>");
	}

	// when less
	if (ComparePageObject.NeedBlockTD > 0) {
		for ( var i = 0; i < ComparePageObject.NeedBlockTD; i++) {
			var index = (ComparePageObject.ValidCount + i);
			ComparePageObject.ArrPageContent.push("<td class=\"pd0"
					+ classNameAdd + "\" style=\"position:relative; z-index:"
					+ (ComparePageObject.NeedBlockTD - i) + "\">");
			if (i == 0) {
				ComparePageObject.ArrPageContent.push("<div id=\"tableHead_"
						+ index + "\" class=\"tableHead_item noBg\">");
			} else {
				ComparePageObject.ArrPageContent.push("<div id=\"tableHead_"
						+ index + "\" class=\"tableHead_item noBg\">");
			}
			ComparePageObject.ArrPageContent.push("<div class=\"top-txt\">媒体"
					+ (index + 1) + "</div>");

			if (i == 0) {
				ComparePageObject.FloatTop.push("</div>");
				ComparePageObject.FloatTop.push("</td>");
			} else {
				ComparePageObject.FloatTop.push("</div></td>");
			}
			ComparePageObject.ArrPageContent.push("</div></td>");
		}
	}
	ComparePageObject.ArrPageContent.push("</tr>");

	ComparePageObject.FloatTop.push("</tr>");
	ComparePageObject.FloatTop.push("</table>");
	$("#topfixed").html(ComparePageObject.FloatTop.join(""));
}

function changeWhenFloatTop() {
	if (ComparePageObject.IsShowFloatTop) {
		// show the Float Top
		if (ComparePageObject.AllCarJson.length > 0) {
			$("#master4,#serial4,#cartype4").prependTo(
					"div[id^='FloatTop_tableHead_'][bit-disabled]");
			// if (ComparePageObject.ValidCount > 0) {
			// for (var i = 0; i < ComparePageObject.ValidCount; i++) {
			// if (!document.getElementById("MasterSelectList_HeadTemp_" + i)
			// || document.getElementById("MasterSelectList_HeadTemp_" + i) ==
			// null)
			// { continue; }
			// // if (typeof
			// (document.getElementById("MasterSelectList_HeadTemp_" + i) !=
			// "undefined")) {
			// // current change state
			// $("#FloatTop_carBox_" + i + " dl").hide();
			// $("#MasterSelectList_HeadTemp_" + i).appendTo("#FloatTop_carBox_"
			// + i);
			// $("#SerialSelectList_HeadTemp_" + i).appendTo("#FloatTop_carBox_"
			// + i);
			// $("#CarTypeSelectList_HeadTemp_" +
			// i).appendTo("#FloatTop_carBox_" + i);
			// // $("#FloatTop_OptArea_" + i).hide();
			// $("#FloatTop_OptArea_" + i).empty();
			// }
			// }
			// }
		} else {
			// hide the Float Top
			if (ComparePageObject.AllCarJson.length > 0) {

				// if (ComparePageObject.ValidCount > 0) {
				// if (ComparePageObject.ValidCount > 0) {
				// for (var i = 0; i < ComparePageObject.ValidCount; i++) {
				// if (!document.getElementById("MasterSelectList_HeadTemp_" +
				// i)
				// || document.getElementById("MasterSelectList_HeadTemp_" + i)
				// == null)
				// { continue; }
				// // if (typeof
				// (document.getElementById("MasterSelectList_HeadTemp_" + i) !=
				// "undefined")) {
				// // current change state
				// $("#FloatTop_carBox_" + i + " dl").show();
				// $("#MasterSelectList_HeadTemp_" + i).appendTo("#carBox_" +
				// i);
				// $("#SerialSelectList_HeadTemp_" + i).appendTo("#carBox_" +
				// i);
				// $("#CarTypeSelectList_HeadTemp_" + i).appendTo("#carBox_" +
				// i);
				// $("#FloatTop_OptArea_" + i).show();
				// // }
				// }
				// }
			}
		}
	} else {
		$("#master4,#serial4,#cartype4").insertBefore(
				"div[id^='tableHead_'][bit-disabled] .recom-car");
	}
}

// create bar for compare
function createBar(arrFieldRow) {
	ComparePageObject.ArrTempBarHTML.length = 0;
	ComparePageObject.ArrTempBarForFloatLeftHTML.length = 0;
	ComparePageObject.ArrTempLeftNavHTML.length = 0;

	if (ComparePageObject.ValidCount > 0) {
		ComparePageObject.ArrTempBarHTML.push("<tr id=\""
				+ arrFieldRow["scrollId"] + "\">");
		var summaryColumn = 0;
		if (ComparePageObject.ValidCount < 5) {
			summaryColumn = 6;
		} else {
			summaryColumn = ComparePageObject.ValidCount + 2;
		}
		ComparePageObject.ArrTempBarHTML.push("<td class=\"pd0\" colspan=\""
				+ summaryColumn + "\">");
		ComparePageObject.ArrTempBarHTML.push("<h2><span>"
				+ arrFieldRow["sFieldTitle"] + "</span></h2>");
		ComparePageObject.ArrTempBarHTML.push("</td>");
		ComparePageObject.ArrTempBarHTML.push("</tr>");

		// 左侧菜单数据
		ComparePageObject.ArrTempLeftNavHTML.push("<li class=\""
				+ (arrFieldRow["sFieldTitle"] == "基本信息》" ? "current" : "")
				+ "\"><a data-target=\"" + arrFieldRow["scrollId"]
				+ "\" href=\"javascript:;\" >" + arrFieldRow["sFieldTitle"]
				+ "</a></li>");
		// ComparePageObject.ArrTempHideLeftNavId.push(arrFieldRow["scrollId"]);
	}
	if (ComparePageObject.ArrTempBarForFloatLeftHTML.length > 0) {
		ComparePageObject.FloatLeft
				.push(ComparePageObject.ArrTempBarForFloatLeftHTML.join(""));
		ComparePageObject.ArrTempBarForFloatLeftHTML.length = 0;
	}
}

// create param for compare
function createPara(arrFieldRow) {
	var firstSame = true, isAllunknown = true, arrSame = [], arrTemp = [], isShowLoop = 0;

	var chkResult = {
		IsSame : true,
		CurrCarIndex : 0,
		CurrParamsValue : 0
	};
	var vantage = (ComparePageObject.IsVantage && arrFieldRow["isVantage"] && arrFieldRow["isVantage"] == "1");
	if (vantage || ComparePageObject.IsShowDiff)
		chkResult = IsFieldSame(arrFieldRow);

	for ( var i = 0; i < ComparePageObject.ValidCount; i++) {
		if (ComparePageObject.AllCarJson[i]) {
			var align="center";
			if(arrFieldRow["align"]=="left"){
				align="";
			}
			var color_class="";
			if  (arrFieldRow["color"] == "orange"){
				color_class="orange";
			}
			if (!chkResult.IsSame && ComparePageObject.IsShowDiff)
				arrTemp.push("<td name=\"td" + i + "\" class=\""+color_class +"\" align='"+align+"'>");
			else if (!chkResult.IsSame && vantage
					&& chkResult.CurrCarIndex != -1) {
				arrTemp.push("<td name=\"td" + i + "\" class=\""+color_class +"\">");
			} else
				arrTemp.push("<td name=\"td" + i + "\" class=\""+color_class +"\" align='"+align+"' >");
			try {
				var sTrPrefix = arrFieldRow["sTrPrefix"];
				var index = arrFieldRow["sFieldIndex"];
				if (ComparePageObject.AllCarJson[i].length <= sTrPrefix) {
					return;
				}
				if (ComparePageObject.AllCarJson[i][sTrPrefix].length <= index) {
					return;
				}
				var field = ComparePageObject.AllCarJson[i][sTrPrefix][index]
						|| "";
				
				if (arrSame.length < 1) {
					arrSame.push(field);
				} else {
					if (field == arrSame[0]) {
						firstSame = firstSame && true;
					} else {
						firstSame = firstSame && false;
					}
				}
				if (field.indexOf("待查") >= 0 || field == "") {
					isAllunknown = true && isAllunknown;
				} else {
					isAllunknown = false;
				}
				if (field.indexOf("有") == 0) {
					arrTemp.push(field);
				} else {
					//标识优势
					if (!chkResult.IsSame && ComparePageObject.IsVantage) {
						var tempFlag = false;
						if (!isNaN(chkResult.CurrParamsValue) && !isNaN(field)) {
							tempFlag = (parseFloat(chkResult.CurrParamsValue) == parseFloat(field));
						} else {
							tempFlag = (chkResult.CurrParamsValue == field);
						}
//						if (chkResult.CurrCarIndex != -1 && tempFlag&& arrFieldRow["isVantage"]&& arrFieldRow["isVantage"] == "1"){
//						//	arrTemp.push("<strong class=\"best\">" + field+ "</strong>");
//							arrTemp.push(field);
//						} else 
						
							arrTemp.push(field);
//						}
					} else{
						arrTemp.push(field);
					}
				}
			} catch (err) {
				arrTemp.push("-");
				firstSame = firstSame && false;
			}
			arrTemp.push("</td>");
		} else {
			arrTemp.push("<td>&nbsp;");
			arrTemp.push("</td>");
		}
		isShowLoop++;
	}
	if (firstSame && ComparePageObject.IsDelSame) {
		return;
	} else {
		if (!isAllunknown) {
			// Is Need Show The Bar
			if (ComparePageObject.ArrTempBarHTML.length > 0) {
				ComparePageObject.ArrPageContent
						.push(ComparePageObject.ArrTempBarHTML.join(""));
				ComparePageObject.ArrTempBarHTML.length = 0;
				// 添加左侧菜单
				ComparePageObject.ArrLeftNavHTML
						.push(ComparePageObject.ArrTempLeftNavHTML.join(''));
				ComparePageObject.ArrTempLeftNavHTML.length = 0;
			} else {
				// ComparePageObject.ArrHideLeftNavIds.push(ComparePageObject.ArrTempHideLeftNavId.join(''));
				// ComparePageObject.ArrTempHideLeftNavId.length = 0;
			}
			if (ComparePageObject.ArrTempBarForFloatLeftHTML.length > 0) {
				ComparePageObject.FloatLeft
						.push(ComparePageObject.ArrTempBarForFloatLeftHTML
								.join(""));
				ComparePageObject.ArrTempBarForFloatLeftHTML.length = 0;
			}

			ComparePageObject.ArrPageContent.push("<tr>");
			if (checkTitleIsThreeLines(arrFieldRow["sFieldTitle"])) {
				ComparePageObject.ArrPageContent
						.push("<th class=\"threeLines\">");
				ComparePageObject.FloatLeft
						.push("<tr><th class=\"threeLines\">"
								+ checkBaikeForTitle(arrFieldRow)
								+ "</th></tr>");
			} else {
				ComparePageObject.ArrPageContent.push("<th class='center'>");
				ComparePageObject.FloatLeft.push("<tr><th>"
						+ checkBaikeForTitle(arrFieldRow) + "</th></tr>");
			}
			ComparePageObject.ArrPageContent
					.push(checkBaikeForTitle(arrFieldRow));
			ComparePageObject.ArrPageContent.push("</th>");
			ComparePageObject.ArrPageContent.push(arrTemp.join(""));
		} else {
			return;
		}
	}
	// when less
	if (ComparePageObject.NeedBlockTD > 0) {
		for ( var i = 0; i < ComparePageObject.NeedBlockTD; i++) {
			if (i > 0) {
				ComparePageObject.ArrPageContent.push("<td class=\"noBg\">");
			} else {
				ComparePageObject.ArrPageContent.push("<td class=\"noBg\">");
			}
			ComparePageObject.ArrPageContent.push("&nbsp;");
			ComparePageObject.ArrPageContent.push("</td>");
		}
	}
	ComparePageObject.ArrPageContent.push("</tr>");
}

// 判断参数值是否相同
function IsFieldSame(arrFieldRow) {
	var tempArray = new Array();
	var paramArray = arrFieldRow["sFieldIndex"].split(',');
	var unitArray = arrFieldRow["unit"].split(',');
	var joinCodeArray = arrFieldRow["joinCode"].split(',');
	var pidArray = arrFieldRow["sPid"].split(',');
	var prefixArray = arrFieldRow["sTrPrefix"].split(',');

	var result = {
		IsSame : true,
		CurrCarIndex : 0,
		CurrParamsValue : 0
	}, tempField = null, allCarFieldArr = [];
	try {
		for ( var i = 0; i < ComparePageObject.ValidCount; i++) {
			if (!ComparePageObject.AllCarJson[i])
				continue;
			var multiField = "";
			for ( var pint = 0; pint < paramArray.length; pint++) {
				// loop every param
				var sTrPrefix = arrFieldRow["sTrPrefix"];
				var index = paramArray[pint];
				if (ComparePageObject.AllCarJson[i].length <= prefixArray[pint]) {
					return;
				}
				if (ComparePageObject.AllCarJson[i][prefixArray[pint]].length <= index) {
					return;
				}
				var field = ComparePageObject.AllCarJson[i][prefixArray[pint]][index]
						|| "";
				multiField = multiField + field;
			}
			// 判断是否是数字 解决 8.2、8.20 现象
			if (!isNaN(multiField) && !isNaN(tempField)) {
				if (parseFloat(multiField) != parseFloat(tempField)
						&& tempField != null)
					result.IsSame = false;
			} else {
				if (multiField != tempField && tempField != null)
					result.IsSame = false;
			}

			if (arrFieldRow["isVantage"] && arrFieldRow["isVantage"] == "1") {
				// 空值排除比较
				var tempMultiField = "";
				if (multiField != "") {
					// 对取值范围值特殊处理
					if (multiField.indexOf('-') != -1) {
						if (arrFieldRow["size"] && arrFieldRow["size"] == "1")
							tempMultiField = multiField.substring(multiField
									.indexOf('-') + 1);
						else
							tempMultiField = multiField.substring(0, multiField
									.indexOf('-'));
					} else
						tempMultiField = multiField;
					// console.log(arrFieldRow["sFieldTitle"] + tempMultiField);
					if (allCarFieldArr.indexOf(tempMultiField) == -1)
						allCarFieldArr.push(tempMultiField);
				}
				if (arrFieldRow["size"] && arrFieldRow["size"] == "1") {
					if (tempMultiField >= allCarFieldArr.max()
							&& tempMultiField != "") {
						result.CurrParamsValue = multiField;
						result.CurrCarIndex = i;
					}
				} else {
					if (tempMultiField <= allCarFieldArr.min()
							&& tempMultiField != "") {
						// console.log(arrFieldRow["sFieldTitle"] + multiField +
						// "come in");
						result.CurrParamsValue = multiField;
						result.CurrCarIndex = i;
					}
				}
			}
			// 上次临时值
			tempField = multiField;
		}
		if (allCarFieldArr.length <= 1) {
			result.CurrCarIndex = -1;
			result.CurrParamsValue = 0;
		}
	} catch (e) {
	}
	return result;
}

// create multi param for compare
function createMulti(arrFieldRow) {
	var paramArray = arrFieldRow["sFieldIndex"].split(',');
	var unitArray = arrFieldRow["unit"].split(',');
	var joinCodeArray = arrFieldRow["joinCode"].split(',');
	var pidArray = arrFieldRow["sPid"].split(',');
	var prefixArray = arrFieldRow["sTrPrefix"].split(',');

	var firstSame = true;
	var isAllunknown = true;
	var arrSame = new Array();
	var arrTemp = new Array();
	var isShowLoop = 0;

	var chkResult = {
		IsSame : true,
		CurrCarIndex : 0,
		CurrParamsValue : 0
	};
	if ((ComparePageObject.IsVantage && arrFieldRow["isVantage"] && arrFieldRow["isVantage"] == "1")
			|| ComparePageObject.IsShowDiff)
		chkResult = IsFieldSame(arrFieldRow);

	// loop every car
	var tempArrMultField = [];
	for ( var i = 0; i < ComparePageObject.ValidCount; i++) {
		if (ComparePageObject.AllCarJson[i]) {
			if (!chkResult.IsSame)
				arrTemp.push("<td name=\"td" + i + "\" >");
			else
				arrTemp.push("<td name=\"td" + i + "\" >");
			try {
				var multiField = "";
				for ( var pint = 0; pint < paramArray.length; pint++) {
					// 组合类型
					if (pidArray[pint] == "577") {
						// 如果当前是 燃油标号 前1项不是汽油的话不显示
						if (multiField.indexOf("汽油") < 0) {
							continue;
						}
					}
					if (pidArray[pint] == "408") {
						// 如果自然吸气直接显示，如果是增压则显示增压方式
						if (multiField.indexOf("增压") < 0) {
							continue;
						} else {
							multiField = "";
						}
					}
					// loop every param
					var sTrPrefix = arrFieldRow["sTrPrefix"];
					var index = paramArray[pint];
					if (ComparePageObject.AllCarJson[i].length <= prefixArray[pint]) {
						return;
					}
					if (ComparePageObject.AllCarJson[i][prefixArray[pint]].length <= index) {
						return;
					}
					var field = ComparePageObject.AllCarJson[i][prefixArray[pint]][index]
							|| "";
					// 档位数 无极变速 不显示
					if (pidArray[pint] == "724") {
						if (isNaN(field) || parseInt(field) <= 0)
							continue;
					}
					// modified by chengl May.31.2012
					if (pidArray[pint] == "577") {
						// 燃油标号 90改为：89或90；93改为：92或93；97改为：95或97；
						switch (field) {
						case "90号":
							field = field + "(北京89号)";
							break;
						case "93号":
							field = field + "(北京92号)";
							break;
						case "97号":
							field = field + "(北京95号)";
							break;
						default:
							break;
						}
					}
					if (field == "待查") {
						field = "";
					}
					if (field.length > 0) {
						if (pidArray[pint] == "659") {
							// 百公里等速油耗速度 合并
							if (field == "综合") {
								field = "(" + field + ")";
							} else {
								field = "(" + field + unitArray[pint] + ")";
							}
						} else {
							field += unitArray[pint] || "";
						}
						multiField = multiField + (joinCodeArray[pint] || "")
								+ field;
					}

					if (arrSame.length < 1) {
						arrSame.push(multiField);
					} else {
						if (multiField == arrSame[0]) {
							firstSame = firstSame && true;
						} else {
							firstSame = firstSame && false;
						}
					}
					if (multiField.indexOf("待查") >= 0 || multiField == "") {
						isAllunknown = true && isAllunknown;
					} else {
						isAllunknown = false;
					}
					if (multiField.indexOf("有") >= 0) {
						multiField = "<span class=\"songti\">●</span>";
					}
					if (multiField.indexOf("选配") >= 0
							&& multiField.indexOf("●") < 0) {
						multiField = "<span class=\"songti\">○</span>";
					}
					if (multiField.indexOf("无") >= 0
							&& multiField.indexOf("●") < 0
							&& multiField.length == 1) {
						multiField = "<span class=\"songti\">-</span>";
					}

					if (pint == 0) {
						// 如果第1项是有，则不显示有，显示第2项
						if (multiField == "<span class=\"songti\">●</span>") {
							multiField = "";
						} else if (multiField == "<span class=\"songti\">○</span>"
								|| multiField == "<span class=\"songti\">-</span>") {
							break;
						} else {
						}
						// 如果第1项是选配或无，则不显示第2项
					}
				}
				// =================每项多个属性对比 2012-04-11 by
				// songkai===================
				firstSame = true;
				if (ComparePageObject.IsDelSame) {
					tempArrMultField.push(multiField);
					var flag = true;
					if (i == ComparePageObject.ValidCount - 1) {
						for ( var k = 0; k < tempArrMultField.length; k++) {
							if (tempArrMultField[k] != multiField) {
								flag = false;
								firstSame = false;
								break;
							}
						}
						if (flag) {
							continue;
						} else {
							// arrTemp.splice(0, arrTemp.length);
							arrTemp = [];
							for ( var m = 0; m < tempArrMultField.length; m++) {
								if (!chkResult.IsSame)
									arrTemp.push("<td name=\"td" + m
											+ "\" class=\"\">");
								else
									arrTemp.push("<td name=\"td" + m + "\" >");
								arrTemp.push(tempArrMultField[m]);
								arrTemp.push("</td>");
							}
						}
					}
				} else {
					arrTemp.push(multiField);
					// if (!chkResult.IsSame && ComparePageObject.IsVantage) {
					// arrTemp.push("<strong class=\"best\">" + multiField +
					// "</strong>");
					// }
					// else
					// arrTemp.push(multiField);
				}
			} catch (err) {
				arrTemp.push("-");
				firstSame = firstSame && false;
			}
			if (!ComparePageObject.IsDelSame)
				arrTemp.push("</td>");
			// ===========================================================
		} else {
			arrTemp.push("<td>&nbsp;");
			arrTemp.push("</td>");
		}
		isShowLoop++;
	}
	// -----------
	if (firstSame && ComparePageObject.IsDelSame) {
		return;
	} else {
		if (!isAllunknown) {
			// Is Need Show The Bar
			if (ComparePageObject.ArrTempBarHTML.length > 0) {
				ComparePageObject.ArrPageContent
						.push(ComparePageObject.ArrTempBarHTML.join(""));
				ComparePageObject.ArrTempBarHTML.length = 0;
				// 添加左侧菜单
				ComparePageObject.ArrLeftNavHTML
						.push(ComparePageObject.ArrTempLeftNavHTML.join(''));
				ComparePageObject.ArrTempLeftNavHTML.length = 0;
			}
			if (ComparePageObject.ArrTempBarForFloatLeftHTML.length > 0) {
				ComparePageObject.FloatLeft
						.push(ComparePageObject.ArrTempBarForFloatLeftHTML
								.join(""));
				ComparePageObject.ArrTempBarForFloatLeftHTML.length = 0;
			}
			ComparePageObject.FloatLeft.push("<tr><th>"
					+ checkBaikeForTitle(arrFieldRow) + "</th></tr>");
			ComparePageObject.ArrPageContent.push("<tr>");
			ComparePageObject.ArrPageContent.push("<th>");
			ComparePageObject.ArrPageContent
					.push(checkBaikeForTitle(arrFieldRow));
			ComparePageObject.ArrPageContent.push("</th>");
			ComparePageObject.ArrPageContent.push(arrTemp.join(""));
			ComparePageObject.LoopTRColor++;
		} else {
			return;
		}
	}
	// when less
	if (ComparePageObject.NeedBlockTD < ComparePageObject.MaxTDLeft) {
		for ( var i = 0; i < ComparePageObject.NeedBlockTD; i++) {
			if (i > 0) {
				ComparePageObject.ArrPageContent.push("<td class=\"noBg\">");
			} else {
				ComparePageObject.ArrPageContent.push("<td>");
			}
			ComparePageObject.ArrPageContent.push("&nbsp;");
			ComparePageObject.ArrPageContent.push("</td>");
		}
	}
	ComparePageObject.ArrPageContent.push("</tr>");
}

// create price for compare
function createPrice(arrFieldRow) {}

// more infomation
function createOther(arrFieldRow) {}

function createIndex(arrFieldRow) {
	if (ComparePageObject.ArrTempBarHTML.length > 0) {
		ComparePageObject.ArrPageContent.push(ComparePageObject.ArrTempBarHTML
				.join(""));
		ComparePageObject.ArrTempBarHTML.length = 0;
	}
	if (ComparePageObject.ArrTempBarForFloatLeftHTML.length > 0) {
		ComparePageObject.FloatLeft
				.push(ComparePageObject.ArrTempBarForFloatLeftHTML.join(""));
		ComparePageObject.ArrTempBarForFloatLeftHTML.length = 0;
	}
	ComparePageObject.FloatLeft.push("<tr class=\"car-focus-index\"><th>"
			+ (arrFieldRow["sFieldTitle"] == "" ? "&nbsp;"
					: arrFieldRow["sFieldTitle"]) + "</th></tr>");
	// more link
	ComparePageObject.ArrPageContent.push("<tr class=\"car-focus-index\">");
	ComparePageObject.ArrPageContent.push("<th>"
			+ (arrFieldRow["sFieldTitle"] == "" ? "&nbsp;"
					: arrFieldRow["sFieldTitle"]) + "</th>");
	var isShowLoop = 0;
	for ( var i = 0; i < ComparePageObject.ValidCount; i++) {
		var csid = ComparePageObject.AllCarJson[i][0][3] != "undefined" ? ComparePageObject.AllCarJson[i][0][3]
				: "";
		var csLevel = ComparePageObject.AllCarJson[i][0][12] != "undefined" ? ComparePageObject.AllCarJson[i][0][12]
				: "";
		if (ComparePageObject.AllCarJson[i]) {
			ComparePageObject.ArrPageContent.push("<td name=\"td" + i + "\" >");
			try {
				ComparePageObject.ArrPageContent
						.push("<span class=\"tdTwoLines\">");
				if (carIndexJson != "undefined") {
					if (carIndexJson[csid] != "undefined") {
						var uvRank = 0;
						var saleRank = 0;
						if (carIndexJson[csid].UVRank != "undefined") {
							uvRank = carIndexJson[csid].UVRank;
						}
						if (carIndexJson[csid].SaleRank != "undefined") {
							saleRank = carIndexJson[csid].SaleRank;
							ComparePageObject.ArrPageContent.push("");
						}
						if (uvRank > 0) {
							ComparePageObject.ArrPageContent
									.push("<p><a target=\"_blank\" href=\"http://index.bitauto.com/guanzhu/s"
											+ csid
											+ "/\">"
											+ csLevel
											+ "关注</a>");
							ComparePageObject.ArrPageContent.push("<span>第<em>"
									+ uvRank + "</em>名</span>");
							ComparePageObject.ArrPageContent.push("</p>");
						} else {
							ComparePageObject.ArrPageContent
									.push("<p>暂无关注数据</p>");
						}
						if (saleRank > 0) {
							ComparePageObject.ArrPageContent
									.push("<p><a target=\"_blank\" href=\"http://index.bitauto.com/xiaoliang/s"
											+ csid
											+ "/\">"
											+ csLevel
											+ "销量</a>");
							ComparePageObject.ArrPageContent.push("<span>第<em>"
									+ saleRank + "</em>名</span>");
							ComparePageObject.ArrPageContent.push("</p>");
						} else {
							ComparePageObject.ArrPageContent
									.push("<p>暂无销量数据</p>");
						}
					}
				}
				ComparePageObject.ArrPageContent.push("</span>");
			} catch (err) {
				ComparePageObject.ArrPageContent.push("-");
			}
			ComparePageObject.ArrPageContent.push("</td>");
		}
		isShowLoop++;
	}
	// when less
	if (ComparePageObject.NeedBlockTD > 0) {
		for ( var i = 0; i < ComparePageObject.NeedBlockTD; i++) {
			if (i > 0) {
				ComparePageObject.ArrPageContent.push("<td class=\"noBg\">");
			} else {
				ComparePageObject.ArrPageContent.push("<td>");
			}
			ComparePageObject.ArrPageContent.push("</td>");
		}
	}
	ComparePageObject.ArrPageContent.push("</tr>");
}

// when match title add link to baike
function checkBaikeForTitle(arrFieldRow) {
	var title, unit;
	title = arrFieldRow["sFieldTitle"];
	unit = arrFieldRow["unit"];
	if (ComparePageObject.BaikeObj == null
			&& typeof (CarChannelBaikeJson) != "undefined"
			&& CarChannelBaikeJson.length > 0) {
		ComparePageObject.BaikeObj = new Object;
		for ( var i = 0; i < CarChannelBaikeJson.length; i++) {
			for ( var key in CarChannelBaikeJson[i]) {
				ComparePageObject.BaikeObj[key] = CarChannelBaikeJson[i][key];
			}
		}
	}
	if (ComparePageObject.BaikeObj && ComparePageObject.BaikeObj[title]) {
		return "<a href='"
				+ ComparePageObject.BaikeObj[title]
				+ "' target='_blank'>"
				+ title
				+ "<em>"
				+ (unit != "" && unit.indexOf(",") == -1 ? "(" + unit + ")"
						: "") + "</em></a>";
	} else {
		return title
				+ "<em>"
				+ (unit != "" && unit.indexOf(",") == -1 ? "(" + unit + ")"
						: "") + "</em>";
	}
}

function checkTitleIsThreeLines(sFieldTitle) {
	var isThreeLines = false;
	if (sFieldTitle == "车身颜色" || sFieldTitle == "座椅颜色" || sFieldTitle == "内饰颜色") {
		isThreeLines = true;
	}
	return isThreeLines;
}

function checkTitleIsTwoLines(sFieldTitle) {
	var isTwoLines = false;
	if (sFieldTitle == "保修政策" || sFieldTitle == "特有技术"
			|| sFieldTitle == "发动机型号" || sFieldTitle == "主动安全-其他"
			|| sFieldTitle == "后悬挂类型" || sFieldTitle == "前悬挂类型") {
		isTwoLines = true;
	}
	return isTwoLines;
}

// add car to compare
function addCarToCompareForSelect(id, name, csName) {
	var newCarID = new Array();
	if (ComparePageObject.AllCarJson.length > 0) {
		if (ComparePageObject.AllCarJson.length == 10) {
			alert("对比媒体不能多于10个");
			return;
		}
		for ( var i = 0; i < ComparePageObject.AllCarJson.length; i++) {
			if (id == ComparePageObject.AllCarJson[i][0][0]) {
				alert("您选择的媒体,已经在对比列表中!");
				return;
			}
			newCarID.push(ComparePageObject.AllCarJson[i][0][0]);
		}
	}
	newCarID.push(id);
	// 删除添加车款后再添加相同车款 页面不刷新
	if (window.location.search == "?carIDs=" + newCarID.join(",") + "") {
		// document.location.href = "/chexingduibi/?carIDs=" +
		// newCarID.join(",") + "&t=" + Math.random() + "#CarHotCompareList";
		location.reload();
	} else {
		var paramsArr = [];
		if (ComparePageObject.IsOperateTheSame)
			paramsArr.push("diff");
		if (ComparePageObject.IsShowDiff)
			paramsArr.push("showdiff");
		if (ComparePageObject.IsVantage)
			paramsArr.push("vantage");

		document.location.href = "/chexingduibi/?carIDs=" + newCarID.join(",")
				+ "#CarHotCompareList"
				+ (paramsArr.length > 0 ? "&" + paramsArr.join("&") : "") + "";
	}
}

function checkIsCloseHotCompare() {
	if (CookieForTempSave.getCookie("UserCloseCarList") == "1") {
		ComparePageObject.IsCloseHotList = true;
	}
}

function closeHotCompare() {
	// $("#trOtherCarListForFloatLeft").empty();
	$(".firstCar_pop").hide();
	// $("#trForPic td,#trForPic th").each(function () {
	// $(this).removeClass("bdbottomnone");
	// });
	CookieForTempSave.setCookie("UserCloseCarList", "1");
	ComparePageObject.IsCloseHotList = true;
	$("#pkButton").show();
}

function showHotCompare(index) {
	$(".firstCar_pop").show();
	CookieForTempSave.clearCookie("UserCloseCarList");
	ComparePageObject.IsCloseHotList = false;
	// $("#pkButton_" + index).hide();
	ajaxOtherCarList(index);
}

// del car from compare
function delCarToCompare(index, e) {
	var newCarIDArr = new Array();
	if (ComparePageObject.ValidCount < 1) {
		alert('没有可删的了');
		return;
	}

	e = e || window.event;
	var target = e.srcElement || e.target;
	if (index >= 0 && ComparePageObject.ValidCount > index
			&& ComparePageObject.AllCarJson.length > index) {
		// //$("td[name='td" + index + "']").html("");
		// //删除效果
		// $(target).closest(".tableHead_item").animate({ width: 0 }, 500,
		// function () {
		// // del Array index object
		// ComparePageObject.AllCarJson.splice(index, 1);
		// if (ComparePageObject.AllCarJson.length == 1) {
		// ComparePageObject.IsOperateTheSame = false;
		// }
		// initPageForCompare();
		// });
		if (ComparePageObject.IsIE) {
			// del Array index object
			ComparePageObject.AllCarJson.splice(index, 1);
			if (ComparePageObject.AllCarJson.length == 1) {
				ComparePageObject.IsOperateTheSame = false;
			}
			initPageForCompare();
		} else {
			$("td[name='td" + index + "'][id!='td_" + index + "']").html("");
			// 删除效果
			$(target).closest(".tableHead_item").fadeOut(300, function() {
				// del Array index object
				ComparePageObject.AllCarJson.splice(index, 1);
				if (ComparePageObject.AllCarJson.length == 1) {
					ComparePageObject.IsOperateTheSame = false;
				}
				initPageForCompare();
			});
		}

	}
}

function moveLeftForCarCompare(index) {
	if (index > 0 && ComparePageObject.ValidCount > index
			&& ComparePageObject.AllCarJson.length > index) {
		swapArray(ComparePageObject.AllCarJson, index - 1, index);
	}
}

function moveRightForCarCompare(index) {
	if (index >= 0 && (ComparePageObject.ValidCount - 1) > index
			&& (ComparePageObject.AllCarJson.length - 1) > index) {
		swapArray(ComparePageObject.AllCarJson, index, index * 1 + 1);
	}
}

// swap Array object and reshow compare content
function swapArray(obj, index1, index2) {
	var temp = obj[index1];
	obj[index1] = obj[index2];
	obj[index2] = temp;
	createPageForCompare(ComparePageObject.IsOperateTheSame);
}

function advantageForCompare() {
	if (ComparePageObject.ValidCount <= 1)
		return;
	// ComparePageObject.IsVantage = (!ComparePageObject.IsVantage) ? true :
	// false;
	if (ComparePageObject.ValidCount > 1) {
		if (ComparePageObject.IsVantage) {
			ComparePageObject.IsVantage = false;
			$("input[type='checkbox'][name='chkAdvantage']").each(
					function(i, n) {
						this.checked = false;
					});
		} else {
			ComparePageObject.IsVantage = true;
			$("input[type='checkbox'][name='chkAdvantage']").each(
					function(i, n) {
						this.checked = true;
					});
		}
		createPageForCompare(ComparePageObject.IsDelSame);
	}
	gotoCheckPage();
	// $(window).scrollTop($(window).scrollTop() + 1);
}
// 显示差异
function showDiffForCompare() {
	if (ComparePageObject.ValidCount <= 1)
		return;
	// ComparePageObject.IsShowDiff = (ComparePageObject.IsShowDiff) ? true :
	// false;
	if (ComparePageObject.ValidCount > 1) {
		if (ComparePageObject.IsShowDiff) {
			ComparePageObject.IsShowDiff = false;
			$("input[type='checkbox'][name='checkboxForDiff']").each(
					function(i, n) {
						this.checked = false;
					});
		} else {
			ComparePageObject.IsShowDiff = true;
			$("input[type='checkbox'][name='checkboxForDiff']").each(
					function(i, n) {
						this.checked = true;
					});
		}
		createPageForCompare(ComparePageObject.IsDelSame);
	}
	gotoCheckPage();
	// $(window).scrollTop($(window).scrollTop() + 1);
}
// 获取多选框参数
function gotoCheckPage() {
	var paramsArr = [];
	if (ComparePageObject.IsOperateTheSame)
		paramsArr.push("diff");
	if (ComparePageObject.IsShowDiff)
		paramsArr.push("showdiff");
	if (ComparePageObject.IsVantage)
		paramsArr.push("vantage");
	// 刷新页面
	if (ComparePageObject.AllCarJson.length > 0) {
		var tempArr = [];
		for ( var i = 0; i < ComparePageObject.AllCarJson.length; i++) {
			tempArr.push(ComparePageObject.AllCarJson[i][0][0])
		}
		document.location.href = "/chexingduibi/?carIDs=" + tempArr.join(",")
				+ "" + "#CarHotCompareList"
				+ (paramsArr.length > 0 ? "&" + paramsArr.join("&") : "")
				+ "&t";
	}
}
// 排除相同项
function delTheSameForCompare() {
	if (ComparePageObject.ValidCount <= 1)
		return;
	// ComparePageObject.IsOperateTheSame =
	// (!ComparePageObject.IsOperateTheSame) ? true : false;

	// js 控制
	if (ComparePageObject.ValidCount > 1) {
		if (!ComparePageObject.IsOperateTheSame) {
			createPageForCompare(true);
			ComparePageObject.IsOperateTheSame = true;
			changeCheckBoxStateByName("checkboxForDelTheSame", true);
		} else {
			createPageForCompare(false);
			ComparePageObject.IsOperateTheSame = false;
			changeCheckBoxStateByName("checkboxForDelTheSame", false);
		}
	}
	gotoCheckPage();
	// $(window).scrollTop($(window).scrollTop() + 1);
}

function changeCheckBoxStateByName(name, state) {
	var checkBoxs = document.getElementsByName(name);
	if (checkBoxs && checkBoxs.length > 0) {
		for ( var i = 0; i < checkBoxs.length; i++) {
			checkBoxs[i].checked = state;
		}
	}
}
// 数组扩展方法
Array.prototype.indexOf = function(value) {
	for ( var i = 0, l = this.length; i < l; i++)
		if (this[i] == value)
			return i;
	return -1;
}
Array.prototype.max = function() {
	return Math.max.apply({}, this)
}
Array.prototype.min = function() {
	return Math.min.apply({}, this)
}

// 绑定下拉选择框
function bindSelectForCompare() {
	var mdvalue = "0", sdvalue = "0";
	// if (CookieForTempSave.getCookie("TempSelectMasterID") != "") {
	// mdvalue = CookieForTempSave.getCookie("TempSelectMasterID");
	// if (CookieForTempSave.getCookie("TempSelectSerialID") != "")
	// { sdvalue = CookieForTempSave.getCookie("TempSelectSerialID"); }
	// }
	// modified by sk 2014.01.02 默认选择框根据选择车款最后一个
	if (ComparePageObject.ValidCount > 0) {
		var lastCarJson = ComparePageObject.AllCarJson[ComparePageObject.AllCarJson.length - 1], carId = lastCarJson[0][0];
		mdvalue = getMasterId(carId);
		sdvalue = lastCarJson[0][3];
	}
	// modified by sk 2013.03.27 广告
	var serialId = 0;
	if (typeof ComparePageObject.AllCarJson[0] != "undefined"
			&& typeof ComparePageObject.AllCarJson[0][0] != "undefined"
			&& ComparePageObject.AllCarJson[0][0][3] != "undefined") {
		serialId = ComparePageObject.AllCarJson[0][0][3];
	}
	if (ComparePageObject.ValidCount == 1
			&& typeof bit_locationInfo != "undefined"
			&& typeof carCompareAdJson != "undefined") {
		var cityId = bit_locationInfo.cityId;
		if (carCompareAdJson["0"] != undefined) {
			cityId = "0";
		}
		if (carCompareAdJson[cityId] != undefined) {
			for ( var i = 0; i < carCompareAdJson[cityId].length; i++) {
				if (carCompareAdJson[cityId][i].serialids.indexOf(serialId) != -1) {
					mdvalue = carCompareAdJson[cityId][i].carad.masterid;
					sdvalue = carCompareAdJson[cityId][i].carad.serialid;
					break;
				}
			}
		}
	}
	ComparePageObject.BSelect = BitA.DropDownListNew({
		container : {
			master : "master4",
			serial : "serial4",
			cartype : "cartype4"
		},
		include : {
			serial : "1",
			cartype : "1"
		},
		dvalue : {
			master : mdvalue,
			serial : sdvalue
		},
		callback : {
			cartype : function(data) {
				setCarDisabled();
			}
		},
		onchange : {
			cartype : function() {
				onchangeCarForSelect();
			}
		}
	});
}

function onchangeCarForSelect(selectObj) {
	var selectBsID = ComparePageObject.BSelect.getValue("master");
	var selectCsID = ComparePageObject.BSelect.getValue("serial");
	// CookieForTempSave.setCookie("TempSelectMasterID", selectBsID);
	// CookieForTempSave.setCookie("TempSelectSerialID", selectCsID);
	addCarToCompareForSelect(ComparePageObject.BSelect.getValue("cartype"));
	fixWidthNormal(selectObj);
}
// 根据媒体获取主品牌ID
function getMasterId(carId) {
	var masterId = 0;
	if (allCarInfo != undefined) {
		for ( var i = 0; i < allCarInfo.length; i++) {
			if (allCarInfo[i].Key == carId) {
				masterId = allCarInfo[i].Value.MasterId;
				break;
			}
		}
	}
	return masterId;
}
// 换车
function setSelectControlForCompare(objID, suffix) {
	if (objID.indexOf('_') >= 0) {
		var index = objID.substring(objID.lastIndexOf('_') + 1, objID.length);
		var serialId = ComparePageObject.AllCarJson[index][0][3];
		var carId = ComparePageObject.AllCarJson[index][0][0];
		var masterId = getMasterId(carId);

		var changeClassName = $(
				"#" + objID + " .change-car-area a[id^='change_car_']").eq(0)
				.attr("class");
		if (changeClassName == "btn-show-car") {
			$("#" + objID + " .change-car-area .popup-change-car").remove();
			$("#" + objID + " .change-car-area a[id^='change_car_']").eq(0)
					.attr("class", "btn-hide-car");
			$("#" + objID).parent().siblings().find(".popup-change-car").hide()
					.parent().children("a[id^='change_car_']").attr("class",
							"btn-show-car");
			$("#" + objID).parent().siblings().find(".popup-recom").hide()
					.parent().children("a:first").attr("class", "btn-show-car");
			// 设置为我推荐设置zindex
			var recomObj = $("#" + objID).parent().nextAll().find(".recom-car")
					.eq(0).parent().parent();
			if (recomObj.length > 0) {
				var recomzIndex = parseInt(recomObj.css("z-index"));
				if (recomzIndex == 11) {
					var prevzIndex = parseInt(recomObj.prev().css("z-index"));
					recomObj.css({
						'z-index' : prevzIndex - 1
					});
				}
			}
		} else {
			$("#" + objID + " .change-car-area a[id^='change_car_']").eq(0)
					.attr("class", "btn-show-car");
			$("#" + objID + " .change-car-area .popup-change-car").hide();
			return;
		}
		// 当前展开层元素的居右宽度
		// var rightWidth = $(document).width() - ($("#" + objID).offset().left
		// + $("#" + objID).outerWidth(true));

		// var changeCarObj = $("#" + objID + " .change-car-area
		// .popup-change-car");
		// if (changeCarObj.length > 0) {
		// changeCarObj.toggle();
		// return;
		// }
		var tempHmtl = [];
		// tempHmtl.push("<div class=\"popup-change-car " + (rightWidth < 435 ?
		// "right" : "") + "\">");
		tempHmtl.push("<div class=\"popup-change-car\">");
		tempHmtl.push("<div class=\"popup-change-car-box\">");
		tempHmtl.push("<div id=\"MasterSelectList" + "_" + suffix + "_" + index
				+ "\" class=\"sel-item-box\" style=\"z-index: 50\"></div>");
		tempHmtl.push("<div id=\"SerialSelectList" + "_" + suffix + "_" + index
				+ "\" class=\"sel-item-box\" style=\"z-index: 40\"></div>");
		tempHmtl.push("<div id=\"CarTypeSelectList" + "_" + suffix + "_"
				+ index
				+ "\" class=\"sel-item-box\" style=\"z-index: 30\"></div>");
		tempHmtl.push("</div>");
		tempHmtl.push("<div class=\"recom-car-list\"><ul id=\"recom-car-list-"
				+ objID + "\"></ul></div>");
		// tempHmtl.push("<a href=\"javascript:closeChangeCarList(" + index +
		// ");\" class=\"btn-close-car\" alt=\"\">关闭</a>");
		tempHmtl.push("</div>");

		$("#" + objID + " .change-car-area").append(tempHmtl.join(''));
		// $("#" + objID + " .change-car-area #change_car_" +
		// index).attr("class", "btn-hide-car").html("收起");

		var currentSelect = ComparePageObject.SelectControlTemp;
		while (currentSelect.indexOf("_ParamSuffix") != -1) {
			currentSelect = currentSelect.replace("_ParamSuffix", "_" + suffix
					+ "_" + index);
		}
		while (currentSelect.indexOf("_BsSuffix") != -1) {
			currentSelect = currentSelect.replace("_BsSuffix", "_" + suffix
					+ "_" + index);
			currentSelect = currentSelect.replace("[masterId]", masterId);
		}
		while (currentSelect.indexOf("_CsSuffix") != -1) {
			currentSelect = currentSelect.replace("_CsSuffix", "_" + suffix
					+ "_" + index);
			currentSelect = currentSelect.replace("[serialId]", serialId);
		}
		while (currentSelect.indexOf("_CarSuffix") != -1) {
			currentSelect = currentSelect.replace("_CarSuffix", "_" + suffix
					+ "_" + index);
			currentSelect = currentSelect.replace("[carId]", carId);
		}
		while (currentSelect.indexOf("[index]") != -1) {
			currentSelect = currentSelect.replace("[index]", "[" + index + "]");
		}
		// alert(currentSelect);
		// setTimeout(function () { eval(currentSelect); }, 200);
		eval(currentSelect);
		// 为我推荐
		ajaxOtherCarList("recom-car-list-" + objID + "", index, 4, false);
		if (ComparePageObject.IsShowFloatTop) {
			changeWhenFloatTop();
		}
	}
}
// 换车根据对比车款 params:车款ID，车款索引位置
function changeCarByIndex(carId, index) {
	var carIds = [];
	if (ComparePageObject.AllCarJson.length > 0) {
		for ( var i = 0; i < ComparePageObject.AllCarJson.length; i++) {
			if (ComparePageObject.AllCarJson[i][0][0] == carId) {
				alert("您选择的媒体,已经在对比列表中!");
				return;
			} else {
				carIds.push(ComparePageObject.AllCarJson[i][0][0]);
			}
		}
	}
	if (carIds.length > index) {
		for ( var i = 0; i < carIds.length; i++) {
			if (i == index) {
				carIds[i] = carId;
				break;
			}
		}
	}
	var paramsArr = [];
	if (ComparePageObject.IsOperateTheSame)
		paramsArr.push("diff");
	if (ComparePageObject.IsShowDiff)
		paramsArr.push("showdiff");
	if (ComparePageObject.IsVantage)
		paramsArr.push("vantage");

	document.location.href = "/chexingduibi/?carIDs=" + carIds.join(",")
			+ "#CarHotCompareList"
			+ (paramsArr.length > 0 ? "&" + paramsArr.join("&") : "") + "";
}
// 换车根据下拉选择框 params:车款索引位置
function onchangeCarForSelectByIndex(index) {
	var selectBsID = ComparePageObject.CreateSelectChange[index]
			.getValue("master");
	var selectCsID = ComparePageObject.CreateSelectChange[index]
			.getValue("serial");
	// CookieForTempSave.setCookie("TempSelectMasterID", selectBsID);
	// CookieForTempSave.setCookie("TempSelectSerialID", selectCsID);
	var newid = ComparePageObject.CreateSelectChange[index].getValue("cartype");
	var newCarID = new Array();
	if (ComparePageObject.AllCarJson.length > 0) {
		for ( var i = 0; i < ComparePageObject.AllCarJson.length; i++) {
			if (ComparePageObject.AllCarJson[i][0][0] == newCarID) {
				alert("您选择的媒体,已经在对比列表中!");
				return;
			} else {
				newCarID.push(ComparePageObject.AllCarJson[i][0][0]);
			}
		}
	}

	if (newCarID.length > index) {

		for ( var i = 0; i < newCarID.length; i++) {
			if (i == index) {
				// current index change
				newCarID[i] = newid;
				break;
			}
		}
	}
	var paramsArr = [];
	if (ComparePageObject.IsOperateTheSame)
		paramsArr.push("diff");
	if (ComparePageObject.IsShowDiff)
		paramsArr.push("showdiff");
	if (ComparePageObject.IsVantage)
		paramsArr.push("vantage");

	document.location.href = "/chexingduibi/?carIDs=" + newCarID.join(",")
			+ "#CarHotCompareList"
			+ (paramsArr.length > 0 ? "&" + paramsArr.join("&") : "") + "";
}
// 上一个媒体对应的 为我推荐
function recomCarList(objId, prevIndex) {
	var carId = ComparePageObject.AllCarJson[prevIndex][0][0], fixWidth = 238;

	// 当前展开层元素的居右宽度
	var rightWidth = $(document).width()
			- ($("#" + objId).offset().left + $("#" + objId).outerWidth(true));
	// 获取上个元素zindex值
	var prevzIndex = parseInt($("#" + objId).parent().prev().css("z-index"));

	var changeClassName = $("#" + objId + " .recom-car a:first").attr("class");
	if (changeClassName == "btn-show-car") {
		$("#" + objId + " .recom-car a:first").attr("class", "btn-hide-car");
		// 向左显示 父级zindex设置最大
		if (rightWidth < fixWidth)
			$("#" + objId).parent().css({
				'z-index' : 11
			});
	} else if (changeClassName == "btn-hide-car") {
		$("#" + objId + " .recom-car a:first").attr("class", "btn-show-car");
		if (rightWidth < fixWidth)
			$("#" + objId).parent().css({
				'z-index' : prevzIndex - 1
			});
	}

	$("#" + objId).parent().siblings().find(".popup-change-car").hide()
			.parent().children("a[id^='change_car_']").attr("class",
					"btn-show-car");
	var changeCarObj = $("#" + objId + " .recom-car .popup-recom");
	if (changeCarObj.length > 0) {
		changeCarObj.toggle();
		return;
	}

	var tempHmtl = [];
	tempHmtl.push("<div class=\"popup-recom "
			+ (rightWidth < fixWidth ? "right" : "") + "\" style=\"\">");
	tempHmtl.push("<div class=\"popup-recom-item\">");
	tempHmtl.push("<h5>大家都用它和谁比</h5>");
	tempHmtl.push("<ul id=\"recom-car-list-nocar-" + objId + "\"></ul>");
	tempHmtl.push("<a href=\"javascript:addAllCarToCompare('" + objId + "',"
			+ prevIndex + ");\" class=\"btn-gray-big\">全部加入对比</a>");
	tempHmtl.push("</div>");
	// tempHmtl.push("<a href=\"javascript:closeRecomCarList(" + prevIndex +
	// ");\" class=\"btn-close-car\">关闭</a>");
	tempHmtl.push("</div>");
	$("#" + objId + " .recom-car").append(tempHmtl.join(''));
	if (carId > 0) {
		ajaxOtherCarList("recom-car-list-nocar-" + objId + "", prevIndex, 5,
				true);
	}
}
// 换车关闭
function closeChangeCarList(index) {
	$("#tableHead_" + index + ",#FloatTop_tableHead_" + index + "").find(
			".popup-change-car").hide().parent().find(
			"a[id='change_car_" + index + "'],a[id='change_car_float_" + index
					+ "']").attr("class", "btn-show-car");
}
// 推荐关闭
function closeRecomCarList(prevIndex) {
	$(
			"#tableHead_" + (prevIndex + 1) + ",#FloatTop_tableHead_"
					+ (prevIndex + 1) + "").find(".recom-car .popup-recom")
			.hide().parent().find("a:first").attr("class", "btn-show-car")
			.text("为我推荐");
}
// 添加所有推荐媒体
function addAllCarToCompare(objId, index) {
	var tempArr = [], tempRecomArr = [];
	for ( var i = 0; i < ComparePageObject.AllCarJson.length; i++) {
		tempArr.push(ComparePageObject.AllCarJson[i][0][0])
	}
	$("#recom-car-list-nocar-" + objId).find('li').each(function(i, n) {
		tempRecomArr.push(this.id.replace("recomCarList_", ""));
	});
	if (tempRecomArr.length <= 0)
		return;
	tempArr = tempArr.concat(tempRecomArr);
	if (tempArr.length > 10) {
		alert("对比媒体不能多于10个");
	} else if (tempArr.length > 0) {
		// closeHotCompare();
		// 推荐类不统计
		if (window.location.search == "?carIDs=" + tempArr.join(",")
				+ "&isrec=1") {
			location.reload();
		} else
			document.location.href = "/chexingduibi/?carIDs="
					+ tempArr.join(",") + "&isrec=1#CarHotCompareList";
	}
}
// 请求推荐媒体
function ajaxOtherCarList(id, index, top, isAdd) {
	if (ComparePageObject.AllCarJson.length > 0
			&& ComparePageObject.AllCarJson.length > index) {
		if (ComparePageObject.LastFirstInterface[ComparePageObject.AllCarJson[index][0][0]]) {
			// 存储请求数据
			var content = getCompareCarListHtml(
					index,
					ComparePageObject.LastFirstInterface[ComparePageObject.AllCarJson[index][0][0]],
					top, isAdd);
			$("#" + id).html(content);
			// $("#recom-car-list-" + index).html(content);
			return;
		}
		$
				.ajax({
					url : ComparePageObject.OtherCarInterface
							+ ComparePageObject.AllCarJson[index][0][0],
					cache : true,
					dataType : 'jsonp',
					jsonpCallback : "callback",
					success : function(data) {
						ComparePageObject.LastFirstInterface[ComparePageObject.AllCarJson[index][0][0]] = data;
						var content = getCompareCarListHtml(index, data, top,
								isAdd);
						$("#" + id).html(content);
						// $("#recom-car-list-" + index).html(content);
					}
				});
	}
}
// 车款是否存在已选车款
function IsExistCarId(carId) {
	var result = false;
	if (ComparePageObject.AllCarJson.length > 0) {
		for ( var i = 0; i < ComparePageObject.AllCarJson.length; i++) {
			if (carId == ComparePageObject.AllCarJson[i][0][0]) {
				result = true;
				break;
			}
		}
	}
	return result;
}
// 大家跟谁比较
function getCompareCarListHtml(index, data, top, isAdd) {
	var carListHtml = [], loop = 0;
	if (top && top <= 0)
		top = 4;
	for ( var i = 0; i < data.length; i++) {
		var carId = data[i].carId;
		var exist = IsExistCarId(carId);
		if (exist) {
			continue;
		}
		loop++;
		if (loop > top)
			break;
		if (isAdd)
			carListHtml.push("<li id=\"recomCarList_" + data[i].carId
					+ "\"><a href=\"javascript:addCarToCompareFromlist("
					+ data[i].carId + ",'" + data[i].carName + "','"
					+ data[i].serialName + "');\"><strong>"
					+ data[i].serialName + "</strong><span>"
					+ data[i].carYearType + "款 " + data[i].carName
					+ "</span> +对比</a></li>");
		else
			carListHtml.push("<li id=\"recomCarList_" + data[i].carId
					+ "\"><a href=\"javascript:changeCarByIndex('"
					+ data[i].carId + "'," + index + ");\"><strong>"
					+ data[i].serialName + "</strong><span>"
					+ data[i].carYearType + "款 " + data[i].carName
					+ "</span> 换车</a></li>");
	}
	return carListHtml.join('');
}

// set img drag
function setImgDrag() {
	$("img[name='imgdrag']")
			.each(
					function(i) {
						$(this)
								.parent()
								.draggable(
										{
											proxy : 'clone',
											revert : true,
											cursor : 'move',
											handle : "img",
											onStartDrag : function() {
												$(this).draggable('proxy').css(
														{
															'z-index' : '999'
														});
												$(this).closest("td").css({
													'z-index' : '999'
												});
												// $(this).draggable('options').cursor
												// = 'move';
												ComparePageObject.DragID = "";
												if (typeof (this.id) != "undefined"
														&& this.id) {
													ComparePageObject.DragID = this.id
															.replace(
																	"draggcarbox_",
																	"");
												}
											},
											onStopDrag : function() {
												$(this).css({
													'left' : '0px',
													'top' : '0px'
												});
												// $(this).draggable('proxy').css({
												// 'z-index': '1' });
												$(this).closest("td").css({
													'z-index' : '1'
												});

												// $(this).draggable('options').cursor
												// = 'move';
												$(".carBox")
														.each(
																function() {
																	$(this)
																			.removeClass(
																					'moving');
																});
												if (ComparePageObject.DragID != ""
														&& ComparePageObject.DropID != ""
														&& ComparePageObject.DragID != ComparePageObject.DropID) {
													swapArray(
															ComparePageObject.AllCarJson,
															ComparePageObject.DragID,
															ComparePageObject.DropID);
												}
												ComparePageObject.DragID = "";
												ComparePageObject.DropID = "";
											}
										});
					});

	$(".sel-car-box").droppable({
		onDragEnter : function(e, source) {
			$(this).addClass('moving');
		},
		onDragLeave : function(e, source) {
			$(this).removeClass('moving');
		},
		onDrop : function(e, source) {
			$(source).draggable('proxy').remove();
			$(this).removeClass('moving');
			ComparePageObject.DropID = "";
			if (typeof (this.id) != "undefined" && this.id) {
				ComparePageObject.DropID = this.id.replace("carBox_", "");
			}
		}
	});
}

// Fix select Width for IE6
function FixWidth(selectObj) {
}

function fixWidthAuto(selectObj) {
	if (ComparePageObject.IE6) {
		$(selectObj).removeClass("car_select_w");
		$(selectObj).addClass("car_select_auto");
	}
}

function fixWidthNormal(selectObj) {
	if (ComparePageObject.IE6) {
		$(selectObj).removeClass("car_select_auto");
		$(selectObj).addClass("car_select_w");
	}
}

function intiSelectControl() {
	var tempLate = [];
	// 2013-12-23 替换下拉列表调用方式 by sk
	tempLate
			.push('ComparePageObject.CreateSelectChange[index] = BitA.DropDownListNew({');
	tempLate
			.push('	container: { master: "MasterSelectList_BsSuffix", serial: "SerialSelectList_CsSuffix", cartype: "CarTypeSelectList_CarSuffix" },');
	tempLate.push('	include: { serial: "1", cartype: "1" },');
	tempLate
			.push('	dvalue: { master: [masterId], serial: [serialId], cartype: [carId] },');
	tempLate
			.push('	callback: { cartype: function (data) { setCarDisabled(); } },');
	tempLate
			.push('	onchange: { cartype: function(){onchangeCarForSelectByIndex([index]);} }');
	tempLate.push('});');
	ComparePageObject.SelectControlTemp = tempLate.join("");
}
// -------------------- Cookie --------------------
var CookieForTempSave = {
	setCookie : function(name, value) {
		document.cookie = name + "=" + escape(value)
				+ "; domain=car.bitauto.com";
	},

	getCookie : function(name) {
		var arr = document.cookie.match(new RegExp("(^| )" + name
				+ "=([^;]*)(;|$)"));

		if (arr != null) {
			return unescape(arr[2]);
		}
		return null;
	},

	clearCookie : function(name) {
		if (CookieForTempSave.getCookie(name)) {
			document.cookie = name + "=;domain=car.bitauto.com";
		}
	}
};

function setTRColorWhenMouse() {
	$('#CarCompareContent tr:gt(0)').hover(function() {
		$(this).addClass("bg-gray");
	}, function() {
		$(this).removeClass("bg-gray");
	});
}

function mathLeftMenuForResize(currScrollLeft, boxOffsetLeft, currScrollTop,
		boxOffsetTop) {
	if (ComparePageObject.ValidCount <= 0)
		return;
	if (boxOffsetLeft < 128 && boxOffsetLeft > 0) {
		$(".btn-show-left-nav").hide();
		$("#left-nav").hide();
	} else if (boxOffsetLeft == 0) {
		// $(".btn-show-left-nav").show();
		$("#left-nav").hide();
		// if (currScrollTop > boxOffsetTop) {
		// if (ComparePageObject.IE6) {
		// $("#left-nav").css({ position: "absolute", top: currScrollTop - 80,
		// left: currScrollLeft - boxOffsetLeft });
		// $(".btn-show-left-nav").css({ position: "absolute", top:
		// currScrollTop - 75, left: currScrollLeft - boxOffsetLeft });
		// }
		// else {
		// $("#left-nav").css({ position: "fixed", top: "112px", left: "0px" });
		// $(".btn-show-left-nav").css({ position: "fixed", top: "118px", left:
		// "0px" });
		// }
		// } else {
		// $("#left-nav").css({ position: "absolute", top: "200px", left:
		// currScrollLeft - boxOffsetLeft });
		// $(".btn-show-left-nav").css({ position: "fixed", top: "118px", left:
		// "0px" });
		// }

	} else {
		$(".btn-show-left-nav").hide();
		if (currScrollTop > boxOffsetTop) {
			$("#left-nav").css({
				left : (boxOffsetLeft - 113 - currScrollLeft)
			});
		}
		$("#left-nav").show();
	}
}
// 左侧菜单操作
// 参数：（当前左侧滚动距离，居左距离，当前距顶距离，距顶距离）
function mathLeftMenu(currScrollLeft, boxOffsetLeft, currScrollTop,
		boxOffsetTop) {
	// 对比媒体大于1时，操作左侧滚动菜单
	if (ComparePageObject.ValidCount <= 0)
		return;

	if (currScrollLeft > boxOffsetLeft) {
		$(".btn-show-left-nav").show();
		// $("#left-nav").hide();
		if (currScrollTop > boxOffsetTop) {
			if (ComparePageObject.IE6) {
				$("#left-nav").css({
					position : "absolute",
					top : currScrollTop - 80,
					left : currScrollLeft - boxOffsetLeft
				});
				$(".btn-show-left-nav").css({
					position : "absolute",
					top : currScrollTop - 75,
					left : currScrollLeft - boxOffsetLeft
				});
			} else {
				$("#left-nav").css({
					position : "fixed",
					top : "112px",
					left : "0px"
				});
				$(".btn-show-left-nav").css({
					position : "fixed",
					top : "118px",
					left : "0px"
				});
			}
		} else {
			$("#left-nav").css({
				position : "absolute",
				top : "200px",
				left : currScrollLeft - boxOffsetLeft
			});
			$(".btn-show-left-nav").css({
				position : "absolute",
				top : "208px",
				left : (currScrollLeft - boxOffsetLeft)
			});
		}
	}
	// else if (currScrollLeft == 0 && boxOffsetLeft == 0) {
	// $(".btn-show-left-nav").show();
	// $("#left-nav").addClass("left-nav-horizontal");
	// }
	else {
		if (currScrollLeft == 0 && boxOffsetLeft > 128) // 左侧滚动0，菜单显示
			$("#left-nav").show();
		// else if (currScrollLeft > 0)
		// $("#left-nav").hide();

		if (currScrollTop > boxOffsetTop) {
			if (ComparePageObject.IE6)
				$("#left-nav").css({
					position : "absolute",
					top : currScrollTop - 80,
					left : "-114px"
				});
			else {
				// $("#left-nav").css({ position: "fixed", top: "112px", left:
				// "82px" });
				$("#left-nav").css({
					position : "fixed",
					top : "112px",
					left : (boxOffsetLeft - 113 - currScrollLeft)
				});
			}
		} else {
			$("#left-nav").css({
				position : "absolute",
				top : "200px",
				left : "-114px"
			});
		}
		$(".btn-show-left-nav").hide();
		$("#left-nav").removeClass("left-nav-horizontal");
	}
}
// 滚动监听 滚动完成后回调函数
function scrollCallback() {
	var scrollsLeft = $(window).scrollLeft(); // 窗口左卷动值
	var boxoffsetLeft = $("#box").offset().left; // 计算box的offleft值
	if (scrollsLeft > boxoffsetLeft) {
		$("#left-nav").fadeOut(1000);
	}
}

$(function() {
	// 回顶按钮
	$(".left-nav .duibi-return-top").click(function() {
		$("html").animate({
			scrollTop : 0
		}, 300); // IE,FF
		$("body").animate({
			scrollTop : 0
		}, 300); // Webkit
	});

	var theid = $("#topfixed");
	var the_lid = $("#leftfixed");
	var thebox = $("#box");
	var thesmall = $("#smallfixed")
	var floatkey;
	// ////20110811修改隐藏显示浮动层
	var idmainoffsettop = $("#main_box").offset().top; // id的 offsettop
	var idmainoffsettop_top = idmainoffsettop + 90 // 上浮动层出现top定位
	var idleftoffsetheight = $("#tableHead_left").height(); // 左侧浮动层出现的top定位
	var idleftwidth = the_lid.width(); // 左侧浮动层的宽度
	// //////////////屏幕改变大小开始
	$(window).resize(
			function() {
				var boxoffset = thebox.offset();
				var boxoffsetLeft = boxoffset.left; // 计算box的offleft值
				var scrollsLeft = $(window).scrollLeft(); // 计算窗口左卷动值
				var scrolls = $(this).scrollTop();
				mathLeftMenuForResize(scrollsLeft, boxoffsetLeft, scrolls,
						idmainoffsettop_top);
				// //////////left 浮动模开始式///////////////////////////
				if (scrollsLeft > boxoffsetLeft) {// 当窗口大小改变时，如果窗口左滚动大于左侧块左位移
					if (window.XMLHttpRequest) { // 非IE6
						the_lid.css({
							position : "fixed",
							top : (idmainoffsettop - scrolls), // +1
							left : 0,
							display : "block"
						});
					} else {// IE6
						the_lid.css({
							position : "absolute",
							top : 0,
							left : scrollsLeft - boxoffsetLeft,
							display : "block"
						});
					}
				} else {
					the_lid.css({
						display : "none"
					});
				}
				// //////////left浮动模式结束//////////////////
				// //////////左上角开始
				if (scrolls > idmainoffsettop_top
						&& scrollsLeft > boxoffsetLeft) {
					if (window.XMLHttpRequest) {
						thesmall.css({
							position : "fixed",
							left : 0,
							top : 0,
							display : "block"
						});
					} else {// IE
						thesmall.css({
							position : "absolute",
							top : scrolls,
							left : scrollsLeft,
							display : "block"
						});
					}
				} else {
					thesmall.css({
						display : "none"
					});
				}
				// //////////左上角结束
				if (floatkey) {// 如果是在浮动状态
					// 如果box的offsetleft =0 说明窗口小， 那么定位left=0 或者 负的leftscroll
					// 如果box的offsetleft >0 说明窗口大，那么定位left=offsetleft 或者
					// leftscroll-offsetleft
					if (boxoffsetLeft == 0) {// 窗口小
						if (scrollsLeft > 0) {
							if (window.XMLHttpRequest) {
								theid.css({
									left : -scrollsLeft
								});
							} else {// IE
								theid.css({
									left : 0
								});
							}
						} else {
							theid.css({
								left : 0
							});
						}
					}
					if (boxoffsetLeft > 0) {// 窗口大
						if (scrollsLeft < boxoffsetLeft) {
							if (window.XMLHttpRequest) {
								theid.css({
									left : boxoffsetLeft - scrollsLeft
								});
							} else {
								theid.css({
									left : boxoffsetLeft
								});
							}
						} else {
							if (window.XMLHttpRequest) {
								theid.css({
									left : -(scrollsLeft - boxoffsetLeft)
								});
							} else {
								theid.css({
									left : boxoffsetLeft
								});
							}
						}
					}
				}
			});
});

// page method --------------------------
var arrField = [ {
	sType : "fieldPic",
	sFieldIndex : "",
	sFieldTitle : "图片",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : ""
}, {
	sType : "bar",
	sFieldIndex : "",
	sFieldTitle : "基本信息>>",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : "",
	scrollId : "params-carinfo"
}, {
	sType : "fieldPara",
	sFieldIndex : "0",
	sFieldTitle : "媒体编号",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : "",
	color:"orange"
}, {
	sType : "fieldPara",
	sFieldIndex : "1",
	sFieldTitle : "媒体类型",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : "",
	color:"orange"
}, {
}, {
	sType : "fieldPara",
	sFieldIndex : "2",
	sFieldTitle : "媒体形式",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : ""
}, {
	sType : "fieldPara",
	sFieldIndex : "3",
	sFieldTitle : "点位属性",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : ""
}, {
	sType : "fieldPara",
	sFieldIndex : "4",
	sFieldTitle : "媒体面积",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : ""
}, {
	sType : "fieldPara",
	sFieldIndex : "5",
	sFieldTitle : "媒体规格",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : ""
}, {
	sType : "fieldPara",
	sFieldIndex : "6",
	sFieldTitle : "制作工艺",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : "",
	isVantage : "1",
	size : "0"
}, {
	sType : "fieldPara",
	sFieldIndex : "7",
	sFieldTitle : "照明情况",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : ""
}, {
	sType : "fieldPara",
	sFieldIndex : "8",
	sFieldTitle : "刊例价",
	sPid : "",
	sTrPrefix : "1",
	unit : "",
	joinCode : ""
}, {
	sType : "bar",
	sFieldIndex : "",
	sFieldTitle : "环境信息>>",
	sPid : "",
	sTrPrefix : "3",
	unit : "",
	joinCode : "",
	scrollId : "params-carbody"
}, {
	sType : "fieldPara",
	sFieldIndex : "0",
	sFieldTitle : "所属区域",
	sPid : "",
	sTrPrefix : "2",
	unit : "",
	joinCode : "",
	color:"orange"
}, {
}, {
	sType : "fieldPara",
	sFieldIndex : "1",
	sFieldTitle : "区域归属",
	sPid : "",
	sTrPrefix : "2",
	unit : "",
	joinCode : "",
	isVantage : "1",
	size : "1",
	color:"orange"
}, {
}, {
	sType : "fieldPara",
	sFieldIndex : "2",
	sFieldTitle : "具体位置描述",
	sPid : "",
	sTrPrefix : "2",
	unit : "",
	joinCode : "",
	isVantage : "1",
	size : "1",
	align:"left"
}, {
	sType : "fieldPara",
	sFieldIndex : "3",
	sFieldTitle : "离地高度",
	sPid : "",
	sTrPrefix : "2",
	unit : "",
	joinCode : "",
	isVantage : "1",
	size : "1"
}, {
	sType : "fieldPara",
	sFieldIndex : "4",
	sFieldTitle : "转角情况",
	sPid : "",
	sTrPrefix : "2",
	unit : "",
	joinCode : "",
	isVantage : "1",
	size : "1"
}, ];
// 元素居中
!function($) {
	$.fn.showCenter = function() {
		var top = ($(window).height() - this.height()) / 2;
		var left = ($(window).width() - this.width()) / 2;
		var scrollTop = $(document).scrollTop();
		var scrollLeft = $(document).scrollLeft();

		if (ComparePageObject.IE6) {
			return this.css({
				position : 'absolute',
				'z-index' : 1100,
				'top' : top + scrollTop,
				left : left + scrollLeft
			}).show();
		} else {
			return this.css({
				position : 'fixed',
				'z-index' : 1100,
				'top' : "200px",
				left : left
			}).show();
		}
	}
}(jQuery);
// 滚动监听
!function($) {

	"use strict";

	function ScrollSpy(element, options) {
		var process = $.proxy(this.process, this), $element = $(element).is(
				'body') ? $(window) : $(element), href;
		this.options = $.extend({}, $.fn.scrollspy.defaults, options);
		this.$scrollElement = $element
				.on('scroll.scroll-spy.data-api', process);
		this.selector = (this.options.target) + ' li > a';
		this.$body = $('body');
		this.refresh();
		this.process();
	}

	ScrollSpy.prototype = {

		constructor : ScrollSpy

		,
		refresh : function() {
			var self = this, $targets, scrollTop = self.$scrollElement
					.scrollTop();

			this.offsets = $([]);
			this.targets = $([]);

			$targets = this.$body
					.find(this.selector)
					.map(
							function(i, n) {
								var $el = $(this), targetName = $el
										.data('target'), targetHeight = $el
										.height(), $targetElement = $("#"
										+ targetName);
								if ($targetElement
										&& ($targetElement.length > 0)) {
									var ElementScrollTop = ($targetElement
											.offset().top
											+ self.options.offset - (i * (targetHeight + 6)));
									if (scrollTop >= ElementScrollTop) {
										self.activate(targetName)
									}
									$el.unbind("click");
									$el
											.bind(
													"click",
													function(e) {
														e.preventDefault();
														$("html,body")
																.animate(
																		{
																			scrollTop : ElementScrollTop + 1
																		},
																		300,
																		function() {
																			if (typeof self.options["callback"] != "undefined") {
																				self.options["callback"]
																						();
																			}
																		});
													});
									return ([ [ ElementScrollTop, targetName ] ])
								} else
									return null;
							}).sort(function(a, b) {
						return a[0] - b[0]
					}).each(function() {
						self.offsets.push(this[0])
						self.targets.push(this[1])
					});
		}

		,
		process : function() {
			var scrollTop = this.$scrollElement.scrollTop(), scrollHeight = this.$scrollElement[0].scrollHeight
					|| this.$body[0].scrollHeight, maxScroll = scrollHeight
					- this.$scrollElement.height(), offsets = this.offsets, targets = this.targets, activeTarget = this.activeTarget, i;
			if (scrollTop >= maxScroll) {
				return activeTarget != (i = targets.last()[0])
						&& this.activate(i)
			}
			for (i = offsets.length; i--;) {
				activeTarget != targets[i];
				if (scrollTop >= offsets[i]
						&& (!offsets[i + 1] || scrollTop <= offsets[i + 1])) {
					this.activate(targets[i])
				}
			}
		}

		,
		activate : function(target) {

			this.activeTarget = target;

			$(this.selector).parent('.current').removeClass('current');

			var currSelector = this.selector + '[data-target="' + target + '"]';

			var active = $(currSelector).parent('li').addClass('current');

			active.trigger('activate');
		}

	}

	var old = $.fn.scrollspy

	$.fn.scrollspy = function(option, callbackFunc) {
		if (callbackFunc && callbackFunc instanceof Function)
			option["callback"] = callbackFunc;
		return this
				.each(function() {
					var $this = $(this), data = $this.data('scrollspy'), options = typeof option == 'object'
							&& option
					if (!data)
						$this.data('scrollspy', (data = new ScrollSpy(this,
								options)))
					if (typeof option == 'string')
						data[option]()
				})
	}

	$.fn.scrollspy.Constructor = ScrollSpy

	$.fn.scrollspy.defaults = {
		offset : 0,
		offsetList : 0
	}

	$.fn.scrollspy.noConflict = function() {
		$.fn.scrollspy = old
		return this
	}

	// $(function () {
	// $('[data-spy="scroll"]').each(function () {
	// var $spy = $(this)
	// $spy.scrollspy($spy.data())
	// })
	// })

}(jQuery);
// 元素交换
!function($) {
	$.fn.clickChange = function(opts) {
		var defaults = {
			speed : 200, // 移动速度
			offset : 0
		}
		var option = $.extend(defaults, opts);

		var animateCallback = function(obj) {
			$(obj).remove();
		}

		this.each(function() {
			var _this = $(this);
			_this.on('click', '.change-car-area .btn-pre-car', function() {
				if (ComparePageObject.IsChange)
					return;
				ComparePageObject.IsChange = true;
				var parent = $(this).closest('.tableHead_item').find(
						".sel-car-move,div[id^='FloatTop_carBox_']").eq(0);
				var prevItem = $(this).closest('.tableHead_item').parent()
						.prev().find(
								".sel-car-move,div[id^='FloatTop_carBox_']")
						.eq(0);
				if (prevItem.length == 0)
					return;
				var index = parent.attr("id").replace("draggcarbox_", "")
						.replace("FloatTop_carBox_", "");
				// ie6 7 没有动画效果
				// if (ComparePageObject.IE6 || ComparePageObject.IE7) {
				if (ComparePageObject.IsIE) {
					// 标记可切换
					ComparePageObject.IsChange = false;
					if (index && option["leftCallback"]) {
						option["leftCallback"](index);
					}
					return;
				}

				var parentLeft = parent.position().left;
				var prevItemLeft = prevItem.position().left;
				parent.css('display', 'none');
				prevItem.css('display', 'none');
				var parentCloneElement = parent.clone();
				var prevCloneElement = prevItem.clone();

				parentCloneElement.insertAfter(parent).css({
					position : 'absolute',
					display : 'block',
					'z-index' : '1000'
				}).animate(
						{
							left : parentLeft - 159
						},
						option.speed,
						function() {
							parent.insertBefore(prevCloneElement).css(
									'display', 'block');
							animateCallback(prevCloneElement);
							// 标记可切换
							ComparePageObject.IsChange = false;

							if (index && option["leftCallback"]) {
								option["leftCallback"](index);
							}
						});
				prevCloneElement.insertAfter(prevItem).css({
					position : 'absolute',
					display : 'block',
					'z-index' : '999'
				}).animate(
						{
							left : parentLeft + 159
						},
						option.speed,
						function() {
							prevItem.insertBefore(parentCloneElement).css(
									'display', 'block');
							animateCallback(parentCloneElement);
						});
			});
			_this.on('click', '.change-car-area .btn-next-car', function() {
				if (ComparePageObject.IsChange)
					return;
				ComparePageObject.IsChange = true;
				var parent = $(this).closest('.tableHead_item').find(
						".sel-car-move,div[id^='FloatTop_carBox_']").eq(0);
				var nextItem = $(this).closest('.tableHead_item').parent()
						.next().find(
								".sel-car-move,div[id^='FloatTop_carBox_']")
						.eq(0);
				var index = parent.attr("id").replace("draggcarbox_", "")
						.replace("FloatTop_carBox_", "");
				if (nextItem.length == 0)
					return;

				// ie6 7 没有动画效果
				// if (ComparePageObject.IE6 || ComparePageObject.IE7) {
				if (ComparePageObject.IsIE) {
					// 标记可切换
					ComparePageObject.IsChange = false;
					if (index && option["rightCallback"]) {
						option["rightCallback"](index);
					}
					return;
				}
				var parentLeft = parent.position().left;
				var nextItemLeft = nextItem.position().left;
				parent.css('display', 'none');
				nextItem.css('display', 'none');
				var parentCloneElement = parent.clone();
				var nextCloneElement = nextItem.clone();
				// alert(parentLeft);
				parentCloneElement.insertAfter(parent).css({
					position : 'absolute',
					display : 'block',
					'z-index' : '1000'
				}).animate({
					left : parentLeft + 159
				}, option.speed, function() {
					parent.insertBefore(nextItem).css('display', 'block');
					animateCallback(nextCloneElement);
					// 标记可切换
					ComparePageObject.IsChange = false;
					if (index && option["rightCallback"]) {
						option["rightCallback"](index);
					}
				});

				nextCloneElement.insertAfter(nextItem).css({
					position : 'absolute',
					display : 'block',
					'z-index' : '999'
				}).animate(
						{
							left : nextItemLeft - 159
						},
						option.speed,
						function() {
							nextItem.insertBefore(parentCloneElement).css(
									'display', 'block');
							animateCallback(parentCloneElement);
						});
			});
			_this.on('click', '.change-car-area .btn-top', function() {
				if (ComparePageObject.IsChange)
					return;
				ComparePageObject.IsChange = true;
				var parent = $(this).closest('.tableHead_item').find(
						".sel-car-move,div[id^='FloatTop_carBox_']").eq(0);
				var prevItem = $(this).closest('.tableHead_item').parent()
						.prev().find(
								".sel-car-move,div[id^='FloatTop_carBox_']")
						.eq(0);
				if (prevItem.length == 0)
					return;
				var index = parent.attr("id").replace("draggcarbox_", "")
						.replace("FloatTop_carBox_", "");
				// ie6 7 没有动画效果
				// if (ComparePageObject.IE6 || ComparePageObject.IE7) {
				if (ComparePageObject.IsIE) {
					// 标记可切换
					ComparePageObject.IsChange = false;
					if (index && option["leftCallback"]) {
						option["leftCallback"](index);
					}
					return;
				}

				var parentLeft = parent.position().left;
				var prevItemLeft = prevItem.position().left;
				parent.css('display', 'none');
				prevItem.css('display', 'none');
				var parentCloneElement = parent.clone();
				var prevCloneElement = prevItem.clone();

				parentCloneElement.insertAfter(parent).css({
					position : 'absolute',
					display : 'block',
					'z-index' : '1000'
				}).animate(
						{
							left : parentLeft - 159
						},
						option.speed,
						function() {
							parent.insertBefore(prevCloneElement).css(
									'display', 'block');
							animateCallback(prevCloneElement);
							// 标记可切换
							ComparePageObject.IsChange = false;

							if (index && option["leftCallback"]) {
								option["leftCallback"](index);
							}
						});
				prevCloneElement.insertAfter(prevItem).css({
					position : 'absolute',
					display : 'block',
					'z-index' : '999'
				}).animate(
						{
							left : parentLeft + 159
						},
						option.speed,
						function() {
							prevItem.insertBefore(parentCloneElement).css(
									'display', 'block');
							animateCallback(parentCloneElement);
						});
			});
		});
	}
}(jQuery)